//
//  EventTypeSelectCell.swift
//  YOKO
//
//  Created by Zoe_G on 16/5/23.
//  Copyright © 2016年 15Tec. All rights reserved.
//

import UIKit

protocol EventTypeSelectedCellDelegate {
    func eventTypeDidSelect(tag: Int)
}

class EventTypeSelectCell: UITableViewCell {

    @IBOutlet weak var shadowView0: UIView!
    @IBOutlet weak var shadowView1: UIView!
    
    var delegate: EventTypeSelectedCellDelegate! = nil
    
    let btnWidth: CGFloat = 24.0
    let btnLeading: CGFloat = 72.0
    let btnTrailing: CGFloat = 28.0
    
    var typeBtns = [UIButton]()
    var selectedTag = 0
    override func awakeFromNib() {
        self.selectionStyle = .None
        super.awakeFromNib()
        // Initialization code
        shadowView0.layer.shadowOffset = CGSizeMake(0, 3)
        shadowView0.layer.shadowColor = UIColor.lightGrayColor().CGColor
        shadowView0.layer.shadowRadius = 3
        shadowView0.layer.shadowOpacity = 0.8
        
        shadowView1.layer.shadowOffset = CGSizeMake(0, -3)
        shadowView1.layer.shadowColor = UIColor.lightGrayColor().CGColor
        shadowView1.layer.shadowRadius = 3
        shadowView1.layer.shadowOpacity = 0.8
        
        //typeBtn
        let widthBetweenBtn = (screenWidth - btnLeading - btnTrailing - btnWidth*CGFloat(YOKOColor.TypeColors.count))/4.0
        
        for i in 0...YOKOColor.TypeColors.count-1 {
            let x = btnLeading + (btnWidth+widthBetweenBtn)*CGFloat(i)
            let y: CGFloat = 24.0
            let btnFrame = CGRectMake(x, y, btnWidth, btnWidth)
            let typeBtn = UIButton(frame: btnFrame)
            typeBtn.tag = i
//            typeBtn.sendAction(#selector(self.typeBtnSelected(_:)), to: typeBtn, forEvent: )
            
            typeBtn.addTarget(self, action: #selector(self.typeBtnSelected(_:)), forControlEvents: .TouchUpInside)
            typeBtn.layer.cornerRadius = btnWidth/2
            typeBtn.backgroundColor = YOKOColor.TypeColors[i]
            self.contentView.addSubview(typeBtn)
            typeBtns.append(typeBtn)
        }
        
    }

    func typeBtnSelected(sender: UIButton){
        //TODO
        let tag = sender.tag
        self.delegate.eventTypeDidSelect(tag)
    }
    
    override func setSelected(selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    
}
